#include "Block.h"

Block::Block(Size size, Color3B color)
{
  this->autorelease();
  Sprite::init();
  //设置颜色
  this->setTextureRect(Rect(Vec2::ZERO, size));
  this->setColor(color);
  this->setContentSize(size);
  this->setAnchorPoint(Vec2::ZERO);
  
}

void Block::setLabel(string label, float fontSize, Color4B textColor)
{
  //添加文字标签
  auto l = Label::create();
  l->setString(label);
  l->setSystemFontSize(fontSize);
  l->setTextColor(textColor);
  auto size = this->getContentSize();
  l->setPosition(size.width / 2, size.height / 2);
  this->addChild(l);
}


void AllBlock::moveDown(Block* blcok)
{
  Size vSize = Director::getInstance()->getVisibleSize();
  for (auto b : blocks) {
	//下降
	b->index--;

	b->runAction(
	  Sequence::create(MoveTo::create(0.1f, Vec2(b->getPositionX(), b->index*vSize.height / 4)), CallFunc::create([&,this]() {
		  if (b->index<0)
		  blocks.eraseObject(b);
	}), nullptr));
  }
}
